//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //堆/栈/队
        // 1.BM42用两个栈实现队列
        Stack<Integer> stack1 = new Stack<Integer>();
        Stack<Integer> stack2 = new Stack<Integer>();

        //规定：stack1为入队操作，stack2为出队操作
        public void push(int node) {
            stack1.push(node);
        }

        public int pop() {
            //1.stack2为空
            if(stack2.isEmpty()) {
                int size = stack1.size();
                for(int i = 0;i < size;i++) {
                    stack2.push(stack1.pop());
                }
                return stack2.pop();
            }else {
                //2.stack2不为空
                return stack2.pop();
            }
        }
        // 2.BM43包含min函数的栈
        Stack<Integer> stack = new Stack<Integer>();
        Stack<Integer> minstack = new Stack<Integer>();
        public void push(int node) {
            //判断minstack是否为空。
            if (minstack.isEmpty()) {
                //为空则不仅将元素压入stack中还需要压入minstack中
                minstack.push(node);
            } else if (node <= minstack.peek()) {
                //不为空则需要与minstack栈顶的元素比较如果小于minstack栈顶的元素则压入minstack中，大于则不需要压入minstack中，只需要压入stack中
                minstack.push(node);
            }
            stack.push(node);
        }
        public void pop() {
            //判断stack的栈顶元素与minstack栈顶元素是否相等
            int ret = stack.pop();
            if(ret == minstack.peek()) {
                minstack.pop();
            }
        }

        public int top() {
            //直接返回stack的栈顶元素
            return stack.peek();
        }

        public int min() {
            //返回minstack栈顶元素
            return minstack.peek();
        }
        // 3.BM44有效括号序列
        Stack<Character> stack = new Stack<Character>();
        int len = s.length();
        char ch = 0;
        if(len == 0 || len == 1) {
            return false;
        }
        for(int i = 0;i < len;i++) {
            if(s.charAt(i) == '{' || s.charAt(i) == '[' || s.charAt(i) == '(') {
                stack.push(s.charAt(i));
            } else {
                if(!stack.isEmpty()) {
                    ch = stack.pop();
                } else {
                    return false;
                }
                char ch1 = s.charAt(i);
                if(!isValidChild(ch,ch1)) {
                    return false;
                }
            }
        }
        if(stack.size() != 0) {
            return false;
        }
        return true;
    }
    private boolean isValidChild(char ch,char ch1) {
        if(ch == '(' && ch1 == ')' || ch == '[' && ch1 == ']' || ch == '{' && ch1 == '}') {
            return true;
        } else {
            return false;
        }
    }
    }
}